<?php
declare (strict_types = 1);

namespace app\common\lib;

#[class('/common/lib/str', '字符串')]
class Str
{
    #[function['getLoginToken', '生成 login token']]
    public static function getLoginToken(string $username = ''): string
    {
        // 生成一个不会重复的字符串
        $str = md5(uniqid(md5((string) microtime(true)), true));
        // 加密
        $token = sha1($str . $username);

        return $token;
    }

    #[function['challenge', '将多个重复的字符串替换成一个']]
    public static function challenge($search, $replace, $challenge)
    {
        do$challenge = str_replace($search, $replace, $challenge, $count);while ($count);

        return $challenge;
    }

}
